﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ENTITY;
using BUS;
using System.Data;

public partial class Pages_DangNhap : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        EntAccount entity = new EntAccount();
        entity.Username = tbx_username.Text.ToString();
        entity.Password = tbx_password.Text.ToString();
        ABusLogin login = new ABusLogin();
        DataTable dt = login.Login(entity);
        Session["ss_username_login"] = null;
        if (dt.Rows.Count == 0)
        {
            lable_default.Text = "Tài khoản không tồn tại.";
        }
        else
        {
            if (dt.Rows[0].ItemArray[0].ToString().Trim() == entity.Username && dt.Rows[0].ItemArray[1].ToString().Trim() == entity.Password)
            {
                if (int.Parse(dt.Rows[0].ItemArray[2].ToString().Trim())== 1)
                {
                    Response.Redirect("~/Admin/AdminPage.aspx",false);
                    Session["ss_username_login"] = dt.Rows[0].ItemArray[0].ToString().Trim();
                }
                else if (int.Parse(dt.Rows[0].ItemArray[2].ToString().Trim()) == 2)
                {
                    Response.Redirect("~/Manager/ManagerPage.aspx",false);
                    Session["ss_username_login"] = dt.Rows[0].ItemArray[0].ToString().Trim();
                }
                else
                {
                    lable_default.Text = "Xin Chào " + entity.Username;
                }
            }

        }
    }
}
